package com.unittec.zk.provider.work.controller;

import com.alibaba.fastjson.JSON;
import com.unittec.zk.provider.log.Log;
import com.unittec.zk.provider.utils.ValidationUtils;
import com.unittec.zk.provider.work.service.WorkPlanService;
import com.unittec.zk.sdk.log.enums.LogOperateEnum;
import com.unittec.zk.sdk.log.enums.LogStatusEnum;
import com.unittec.zk.sdk.root.domain.GatewayRequest;
import com.unittec.zk.sdk.root.domain.Result;
import com.unittec.zk.sdk.root.enums.BizCode;
import com.unittec.zk.sdk.root.enums.BizCodeEnum;
import com.unittec.zk.sdk.work.request.*;
import com.unittec.zk.sdk.work.response.Res202000;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api(tags = "工作计划管理")
public class WorkPlanController {

    @Resource
    private Log log;

    @Resource
    private WorkPlanService service;
    
    //工作计划-增/改
    @RequestMapping(value = "/202015", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "工作计划-增/改", notes = "工作计划-增/改")
    public Result<Res202000> saveOrUpdateWorkplan(@RequestBody GatewayRequest<Req202015> req) {
        log.debug(req, "saveOrUpdateWorkplan {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res202000 res202000 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object o = service.saveOrUpdateWorkplan(req.getContent());
            res202000 = new Res202000();
            res202000.setObject(o);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("202015", JSON.toJSONString(req), "工作计划-增/改", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "saveOrUpdateWorkplan {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("202015", JSON.toJSONString(req), "工作计划-增/改", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res202000);
        } else {
            log.addOperateLog("202015", JSON.toJSONString(req), "工作计划-增/改", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }
    }

    //工作计划-我创建的-分页
    @RequestMapping(value = "/202016", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "工作计划-我创建的-分页", notes = "工作计划-我创建的-分页")
    public Result<Res202000> getWorkplanPage(@RequestBody GatewayRequest<Req202016> req) {
        log.debug(req, "getWorkplanPage {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res202000 res202000 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object o = service.getWorkplanPage(req.getContent());
            res202000 = new Res202000();
            res202000.setObject(o);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("202016", JSON.toJSONString(req), "工作计划-我创建的-分页", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "getWorkplanPage {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("202016", JSON.toJSONString(req), "工作计划-我创建的-分页", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res202000);
        } else {
            log.addOperateLog("202016", JSON.toJSONString(req), "工作计划-我创建的-分页", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }
    }
    
    //工作计划-删除
    @RequestMapping(value = "/202017", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "工作计划-删除", notes = "工作计划-删除")
    public Result<Res202000> delWorkplan(@RequestBody GatewayRequest<Req202017> req) {
        log.debug(req, "delWorkplan {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res202000 res202000 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object o = service.delWorkplan(req.getContent());
            res202000 = new Res202000();
            res202000.setObject(o);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("202017", JSON.toJSONString(req), "工作计划-删除", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "delWorkplan {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("202017", JSON.toJSONString(req), "工作计划-删除", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res202000);
        } else {
            log.addOperateLog("202017", JSON.toJSONString(req), "工作计划-删除", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }
    }

    //工作计划-我创建的-详情
    @RequestMapping(value = "/202018", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "工作计划-我创建的-详情", notes = "工作计划-我创建的-详情")
    public Result<Res202000> getDetails1(@RequestBody GatewayRequest<Req202018> req) {
        log.debug(req, "getDetails1 {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res202000 res202000 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object o = service.getDetails1(req.getContent());
            res202000 = new Res202000();
            res202000.setObject(o);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("202018", JSON.toJSONString(req), "工作计划-我创建的-详情", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "getDetails1 {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("202018", JSON.toJSONString(req), "工作计划-我创建的-详情", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res202000);
        } else {
            log.addOperateLog("202018", JSON.toJSONString(req), "工作计划-我创建的-详情", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }
    }
    
    //工作计划-我参与的-分页
    @RequestMapping(value = "/202019", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "工作计划-我参与的-分页", notes = "工作计划-我参与的-分页")
    public Result<Res202000> getMyWorkPlanPage(@RequestBody GatewayRequest<Req202019> req) {
        log.debug(req, "getMyWorkPlanPage {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res202000 res202000 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object o = service.getMyWorkPlanPage(req.getContent());
            res202000 = new Res202000();
            res202000.setObject(o);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("202019", JSON.toJSONString(req), "工作计划-我参与的-分页", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "getMyWorkPlanPage {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("202019", JSON.toJSONString(req), "工作计划-我参与的-分页", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res202000);
        } else {
            log.addOperateLog("202019", JSON.toJSONString(req), "工作计划-我参与的-分页", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }
    }

    /**工作计划-我参与的-详情-工作进展
     *
     * @param req
     * @return
     */
    @PostMapping("/202021")
    @ResponseBody
    @ApiOperation(value = "工作计划-我参与的-详情-工作进展", notes = "工作计划-我参与的-详情-工作进展")
    public Result<Res202000> getMyWorkProgress(@RequestBody GatewayRequest<Req202021> req) {
        log.debug(req, "getMyWorkProgress {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res202000 res202000 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object o = service.getMyWorkProgress(req.getContent());
            res202000 = new Res202000();
            res202000.setObject(o);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("202021", JSON.toJSONString(req), "工作计划-我参与的-详情-工作进展", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "getMyWorkProgress {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("202021", JSON.toJSONString(req), "工作计划-我参与的-详情-工作进展", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res202000);
        } else {
            log.addOperateLog("202021", JSON.toJSONString(req), "工作计划-我参与的-详情-工作进展", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }


    }
}
